package com.controller;

import com.common.paging.PagingData;
import com.dto.excution.LoginExcution;
import com.entity.AnnouncementInfo;
import com.entity.BannerInfo;
import com.enums.LoginEnum;
import com.service.BillService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/11/30 0030.
 */
@RestController
@RequestMapping("bill")
public class BillController {
    @Autowired
    private BillService billService;

    @ApiOperation(value = "插入流水")
    @PostMapping(value = "/insertBill")
    @ResponseBody
    public int insertBill(Integer userId, BigDecimal money, Integer types, String description) {
        int res = billService.insertBill(userId, money, types, description);
        return res;
    }

    @ApiOperation(value = "查账户余额和流水")
    @PostMapping(value = "/findMoneyAndBill")
    @ResponseBody
    public Map findMoneyAndBill(Integer userId, Integer limit) {
        Map res = billService.findMoneyAndBill(userId, limit);
        return res;
    }

    @ApiOperation(value = "查询轮播图")
    @PostMapping(value = "/findBanner")
    @ResponseBody
    public List<BannerInfo> findBanner(Integer type) {
        List<BannerInfo> list = billService.findBanner(type);
        return list;
    }

    @ApiOperation(value = "查询公告")
    @PostMapping(value = "/findAnnouncement")
    @ResponseBody
    public List<AnnouncementInfo> findAnnouncement(Integer type) {
        List<AnnouncementInfo> list = billService.findAnnouncement(type);
        return list;
    }

    @ApiOperation(value = "新增父子关系表")
    @PostMapping(value = "/insertUserP")
    @ResponseBody
    public int insertUserP(Integer userId, Integer pid) {
        int success = billService.insertUserP(userId, pid);
        return success;
    }

    @ApiOperation(value = "后台/查询已认证的老师名师值")
    @PostMapping(value = "/findCerTeacherValueList")
    @ResponseBody
    public PagingData findCerTeacherValueList(Integer page, Integer length, String search) {
        page = (page - 1) * 10;
        PagingData pagingData = billService.findCerTeacherValueList(page, length, search);
        return pagingData;
    }

    @ApiOperation(value = "后台/修改老师名师值和isValue")
    @PostMapping(value = "/editTeacherValue")
    @ResponseBody
    public LoginExcution<Void> editTeacherValue(Integer id, Integer teacherValue) {
        int edit = billService.editTeacherValue(id, teacherValue);
        if (edit > 0) {
            return new LoginExcution<Void>(null, LoginEnum.SETSUCCESS);
        } else {
            return new LoginExcution<Void>(null, LoginEnum.SETFAIL);
        }
    }

    @ApiOperation(value = "后台/查二维码注册登陆量")
    @PostMapping(value = "/findRigLoginCount")
    @ResponseBody
    public List findRigLoginCount() {
        List list = billService.findRigLoginCount();
        return list;
    }

    @ApiOperation(value = "后台/查询退款管理")
    @PostMapping(value = "/findRefundRecord")
    @ResponseBody
    public PagingData findRefundRecord(Integer page, Integer length) {
        page = (page - 1) * 10;
        PagingData pagingData = billService.findRefundRecord(page, length);
        return pagingData;
    }

    @ApiOperation(value = "后台/修改退款状态和订单退款状态")
    @PostMapping(value = "/updateRefundRecord")
    @ResponseBody
    public int updateRefundRecord(Integer refundId, Integer recordId, Integer type) {
        return billService.updateRefundRecord(refundId, recordId, type);
    }

    @ApiOperation(value = "查询是否有相同openId的")
    @PostMapping(value = "/findOpenIdCon")
    @ResponseBody
    public int findOpenIdCon(String openId) {
        int count = billService.findOpenIdCon(openId);
        return count;
    }

    /**
     * 查询完成的订单总数
     * @param userId 用户id
     * @param type  1学生2老师
     * @return
     */
    @ApiOperation(value = "查询自己已完成的订单总数")
    @PostMapping(value = "/findordersum")
    @ResponseBody
    public int findordersum(Integer userId, Integer type) {
        return  billService.findordersum(userId,type);
    }

}
